﻿using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Runtime.Serialization;

using SBPweb.PROvibe.Server.Framework.Contracts;
using SBPweb.PROvibe.Server.Framework.Contracts.Parameters;

namespace SBPweb.PROvibe.Server.Framework.Actors.Parameters
{

    [DataContract(Namespace = "http://schemas.datacontract.org/2004/07/SBPweb.PROvibe.Shared.Actors")]
    public class EntryInitializationParameter : IEntryInitializationParameter
    {

        public EntryInitializationParameter()
        {
        }

        public EntryInitializationParameter(object value)
        {
            Value = value;
        }

        [DataMember(IsRequired = true)]
        public object Value
        {
            get;
            set;
        }

        public static string Serialize(IEntryInitializationParameter parameter)
        {
            DataContractSerializer dcs = new DataContractSerializer(parameter.GetType());
            TextWriter tw = new StringWriter();
            XmlWriter xw = XmlWriter.Create(tw); //, xws);
            dcs.WriteObject(xw, parameter);
            xw.Flush();
            return tw.ToString();
        }

    }

    [DataContract(Namespace = "http://schemas.datacontract.org/2004/07/SBPweb.PROvibe.Shared.Actors")]
    public class EntryInitializationParameter<TValue> : EntryInitializationParameter, IEntryInitializationParameter<TValue>
    {

        public EntryInitializationParameter()
            : base()
        {
        }

        public EntryInitializationParameter(TValue value)
            : base(value)
        {
            Value = value;
        }

        //[DataMember(IsRequired = false)]
        public new TValue Value
        {
            get
            {
                return (TValue)base.Value;
            }
            set
            {
                base.Value = value;
            }
        }

    }

}